﻿@model LeadMaster.Models.CallCentres

<script type="text/javascript" src="../../Scripts/jquery.fileupload.js"></script>

<style type="text/css">
#divProfile label
{
    width: 150px;
}

.text-box
{
    width: 300px;
    font-family: Trebuchet MS;
    font-size: 20px;
    letter-spacing: .1em;
}
</style>
<div id="divProfile">
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend style="width: 300px;">Add  
        @switch (Model.Category)
        {
            case "N":
                @:Installer
                break;
            case "I":
                @:Introducer
                break;
            case "D":
                @:DEA/GDA
                break;
            case "E":
                @:Engineer
                break;
            case "C":
                @:Client User
                break;
            default:
                @:Love Your Earth
                break;
        }</legend>
        <input type="hidden" name="persontype" value="@(ViewBag.PersonType)" />

        <div class="spacer"></div>

        <div class="editor-label">
            <label>Main Contact Name *</label>
            @Html.EditorFor(model => model.Contact1)
            @Html.ValidationMessageFor(model => model.Contact1)
        </div>
        <div class="spacer userentry"></div>
        <div class="editor-label  userentry">
            @Html.LabelFor(model => model.CompanyName)
            @Html.EditorFor(model => model.CompanyName)
            @Html.ValidationMessageFor(model => model.CompanyName)
        </div>
        <div class="spacer"></div>
        <div class="editor-label" style="width: 800px;">
            <label>Photo/Logo</label>
            <span style="font-size: 0px;" class="btn btn-success fileinput-button" id="spanupload">
            <i class="glyphicon glyphicon-plus"></i>
            <input class="fileupload" id="fileupload" type="file" name="files[]" data-id="@Model.CallCentreID" alt="Click to select Picture to upload" />
            </span>
            <label id="lblfilename">@Model.pic</label>
            <div style="width: 552px;">
            <div class="progress" style="width: 400px; float: right; ">
                <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%; background-color: #339966; ">
                <span class="sr-only">0% Complete</span>
                </div>
            </div>  
            </div>
            
        </div>
        <div class="spacer userentry"></div>
        <div class="editor-label userentry" style="width: 800px;">
        <label>Company Number</label>
        @Html.TextBoxFor(model => model.CompanyNumber)
        @Html.ValidationMessageFor(model => model.CompanyNumber)
        </div>
        <div class="spacer userentry"></div>
        <div class="editor-label userentry">
            @Html.LabelFor(model => model.VATnumber)
            @Html.TextBoxFor(model => model.VATnumber)
            @Html.ValidationMessageFor(model => model.VATnumber)
        </div>

        <div class="spacer"></div>
        <div class="editor-label" style="width: 552px; vertical-align: top;">
            <div style="float: left;">
            <label>Address *</label>
            </div>
            <div class="editor-label" style="float: right; ">
                @Html.TextAreaFor(model => model.address, new { style = "background-color: #FFFF66; font-family: 'Trebuchet MS'; font-size: 10px; color: #333333; width:400px; height: 80px;" })
                @Html.ValidationMessageFor(model => model.address)
            </div>
        </div>
        <div class="spacer"></div>
        <div class="editor-label">
            <label>Postcode *</label>
            @Html.EditorFor(model => model.Postcode)
            @Html.ValidationMessageFor(model => model.Postcode)
        </div>
        <div class="spacer"></div>
        <div class="editor-label">
            <label>Telephone *</label>
            @Html.EditorFor(model => model.Telephone)
            @Html.ValidationMessageFor(model => model.Telephone)
        </div>
        <div class="spacer"></div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Mobile)
            @Html.EditorFor(model => model.Mobile)
            @Html.ValidationMessageFor(model => model.Mobile)
        </div>
        <div class="spacer"></div>
        <div class="editor-label">
            <label>Email *</label>
            @Html.EditorFor(model => model.Email1)
            @Html.ValidationMessageFor(model => model.Email1)
        </div>

        @if (@ViewBag.PersonType == "I")
        {
        <div class="spacer"></div>
        <div class="editor-label">
            @Html.LabelFor(model => model.ConfirmedTC)
            I/we 
            <select name='ConfirmedTC' id='ConfirmedTC' @(Model.ConfirmedTC == true ? "disabled" : " ") style="font-family: 'Trebuchet MS'; font-size: 14px">
            <option value="false">Select</option>
            <option value="true" @(Model.ConfirmedTC == true ? "selected" : " ")>
            @if (Model.ConfirmedTC == true)
            {
            @:Agreed @Model.TCConfirmedDate.ToString()
            }
            else
            {
            @:Agree
            }
            </option>
            <option value="false" @(Model.ConfirmedTC == false ? "selected" : " ")>Disagree</option>
            </select> to the <a id="seeTC">Terms and Conditions</a>
            @Html.ValidationMessageFor(model => model.ConfirmedTC)
            @if (Model.ConfirmedTC == true)
            {
            @Html.HiddenFor(m => m.ConfirmedTC)
            @Html.HiddenFor(m => m.TCConfirmedDate)
            }
        </div>
        }

        @if (this.User.IsInRole(LeadMaster.Properties.ApplicationRoles.Operations) ||
            (this.User.IsInRole(LeadMaster.Properties.ApplicationRoles.Operations) && @ViewBag.PersonType == "N"))
        {
        <div class="spacer"></div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Notes)<br />
            @Html.TextAreaFor(model => model.Notes, new { @class = "notes" })
            @Html.ValidationMessageFor(model => model.Notes)
        </div>
        }

        @if ((this.User.IsInRole(LeadMaster.Properties.ApplicationRoles.Operations) && Model.Category == "I") ||
            (this.User.IsInRole(LeadMaster.Properties.ApplicationRoles.Client) && Model.Category == "N") ||
            (this.User.IsInRole(LeadMaster.Properties.ApplicationRoles.Client) && Model.Category == "C") ||
            (this.User.IsInRole(LeadMaster.Properties.ApplicationRoles.Installer) && Model.Category == "N") ||
            this.User.IsInRole(LeadMaster.Properties.ApplicationRoles.Installer) && Model.Category == "E")
        {
            if (!(Model.Category == "E" || Model.Category == "N"))
            {
            <div class="spacer"></div>
            <div class="editor-label">
                @Html.LabelFor(model => model.Region.Description)
                @Html.DropDownList("RegionsID", null, "Binding Region ?")
                @Html.ValidationMessageFor(model => model.active)
            </div>
            }            
        <div class="spacer"></div>
        <div class="editor-label">
            @Html.LabelFor(model => model.active)
            @Html.EditorFor(model => model.active)
            @Html.ValidationMessageFor(model => model.active)
        </div>
        <div class="spacer"></div>
        <div class="editor-label">
            @Html.Label("User Name")
            @Html.TextBoxFor(m => m.UserName)
        </div>
        <div class="spacer"></div>
        <div class="editor-label">
            @Html.Label("Password")
            @Html.TextBox("Password")
        </div>
        }
        <div class="spacer"></div>
        @Html.HiddenFor(m => m.pic)
        <div class="spacer"></div>
        @if (ViewBag.EnterUser == true)
        {
            @:<input type="hidden" name="EnterUser" value="true" />
            @Html.HiddenFor(m => m.OwnedBy)
        }
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}
</div>
<div id="divTC" class="overlay">
@RenderPage("TermsConditions.cshtml")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

<script type="text/javascript">
    $(document).ready(function () {

        @if (ViewBag.EnterUser == true)
        {
            @:$(".userentry").hide();
        }

        $('#cancelbutton').click(function () {
            $('#pic').val($('#originalPicture').val());
            $('#frmEditProfile').attr('action', 'CancelProfile');
            $('#frmEditProfile').submit();
        });

        $('.fileupload').fileupload({
            dataType: 'json',
            url: '/CallCentres/Upload',
            autoUpload: true,
            done: function (e, data) {
                $.ajax({
                    url: "/CallCentres/RegisterPicFile",
                    type: "POST",
                    data: {
                        id: $(this).data("id"),
                        filename: data.result.name
                    }
                });
                $('#lblfilename').text("File Uploaded : " + data.result.name);
                $("<input type='hidden' name='ListUserAnswers[" + data.id.toString() + "].UserAnswer' value='" + data.result.name + "' />").insertAfter('#MainTable');
                $('#picchanged').val('true');
                $('#pic').val(data.result.name);
                $('#introducerpic').attr('src', '../../ClientImages/' + data.result.name);
            }
        }).on('fileuploadprogressall', function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('.progress .progress-bar').css('width', progress + '%');
        });

        $("#seeTC").click(function () {
            $("#divTC").dialog("open");
        });


        $("#divTC").dialog(
        {
            autoOpen: false,
            width: 900,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: ['middle', 20],
            modal: true,
            dialogClass: 'notitle',
            buttons: {
                Close: function () {
                    $(this).dialog("close");
                }
            }
        });


    });

</script>
